package com.jason.java.lib;

import java.util.Random;

public class RandomDemo {

    public static void main(String[] args) {

        random1();
        random2();
        random3();
    }

    /**
     * new Random()
     */
    public static void random1() {
        System.out.println("method 1 ---------");
        Random r = new Random(1);
        for (int i= 0; i < 5; i++) {
            int ran1 = r.nextInt(100);
            System.out.println(ran1);
        }
    }

    /**
     * Math.random()
     */
    public static void random2() {
        System.out.println("method 2 --------");
        int max=100,min=1;
        int ran2 = (int) (Math.random()*(max-min)+min);
        System.out.println(ran2);
    }

    /**
     * currentTimeMillis()
     */
    public static void random3() {
        System.out.println("method 3 --------");
        int max=100,min=1;
        long randomNum = System.currentTimeMillis();
        int ran3 = (int) (randomNum%(max-min)+min);
        System.out.println(ran3);
    }
}
